﻿package nl.joeyvandijk
{
	import flash.display.Sprite;
	import flash.display.Shape;
	import flash.display.LineScaleMode;
	import flash.display.CapsStyle;
	import flash.display.JointStyle;
	import flash.text.TextField;
	import flash.text.AntiAliasType;
	import flash.text.TextFormat;
	import caurina.transitions.Tweener;
	
	public class Preloader extends Sprite
	{
		private var backLine:Shape = new Shape();
		private var line:Shape = new Shape();
		private var text:TextField;
		
		public function Preloader()
		{
			//create background
			
			//create line background
			backLine.graphics.beginFill(0xffffff,1);
			backLine.graphics.drawRect(0,0,200,4);
			backLine.graphics.endFill();
			addChild(backLine);
			
			//create line
			line.graphics.beginFill(0xff0000,1);
			line.graphics.drawRect(0,0,196,2);
			line.graphics.endFill();
			line.x = 2;
			line.y = 1;
			line.scaleX = 0;
			addChild(line);
			
			//create textfield
			var tf:TextFormat = new TextFormat();
			tf.size = 10;
			tf.color = 0xffffff;
			tf.kerning = true;
			tf.font = '_sans';
			
			text = new TextField();
			text.defaultTextFormat = tf;
			text.selectable = false;
			text.embedFonts = false;
			text.antiAliasType = AntiAliasType.ADVANCED;
			text.text = '0%';
			text.x = backLine.width - text.textWidth;
			text.y = 6;
			addChild(text);
		}
		
		public function change(input:uint):void
		{
			line.scaleX = input/100;
			line.x = 2;
			
			text.text = input.toString()+'%';
			text.x = backLine.width - text.textWidth;
		}
		
		public function hide():void
		{
			Tweener.removeTweens(line);
			Tweener.addTween(line, {alpha:0,time:3,transition:'easeOutExpo'});
			Tweener.removeTweens(backLine);
			Tweener.addTween(backLine, {alpha:0,time:3,transition:'easeOutExpo'});
			text.visible = false;
		}
	}
}